FLOPPY_IMAGE	=a.img
HDA_IMAGE	=c.img
HDB_IMAGE	=d.img

SUBDIRS		=boot lib kernel

help:
	@echo "    prepare     - create disk images"
	@echo "    pigos       - make Pigos kernel"
	@echo "    qemu        - run Pigos in Qemu"
	@echo "    debug       - run Pigos in Qemu with gdbserver"
	@echo "    box         - run Pigos in Bochs"
	@echo "    clean       - clean all"
	@echo "    tool        - make tools"
	@echo "    usr         - make some user programs"
	@echo "    world       - make disk images, Pigos, tools and user programs"

world: prepare pigos tool usr

pigos:
	@for dir in $(SUBDIRS);do make -C $$dir || exit 1;done

qemu: pigos
	qemu -fda $(FLOPPY_IMAGE) -hda $(HDA_IMAGE) -hdb $(HDB_IMAGE) -boot a  --no-kqemu &

debug: pigos
	qemu -S -fda $(FLOPPY_IMAGE) -hda $(HDA_IMAGE) -hdb $(HDB_IMAGE) -boot a  --no-kqemu &

box: pigos
	bochs -q -f bochsrc.bxrc

tool:
	make -C tools

usr:
	make -C usr

clean:
	@for dir in $(SUBDIRS);do make clean -C $$dir || exit 1;done
	make clean -C tools
	make clean -C usr

prepare:
	dd if=/dev/zero of=$(FLOPPY_IMAGE) bs=512 count=2880 # 1.44M
	dd if=/dev/zero of=$(HDA_IMAGE) bs=512 count=2016    # this must be same with bochsrc.bxrc
	dd if=/dev/zero of=$(HDB_IMAGE) bs=512 count=2016    # this must be same with bochsrc.bxrc
